window.onload=function(){
    var ws=new WebSocket("ws://zha-ita077-w7:8080/spring-merchant/ws/merchant");
    ws.onmessage=function(event){
       var res = JSON.parse(event.data);
       console.log(event.data);
       
       
       if(res.code==1){
    	   if(res.data=="white_list"){
    		   
    		   swal({
    			   title: "status",
    			   text: "you have add to white list,forward to order page",
    			   type: "info",
    			   showCancelButton: false,
    			   confirmButtonText: "forward now",
    			   closeOnConfirm: false,
    			 },
    			 function(isConfirm){
    				 if (isConfirm) {
    					   window.location.href = "/spring-merchant/views/orders";
    				}else{
    					
    				}
    			 });
    	   }
    	   
    	   if(res.data=="black_list"){
	    		   
	    		   swal({
	    			   title: "status",
	    			   text: "you have add to black list,forward to login page",
	    			   type: "info",
	    			   showCancelButton: false,
	    			   confirmButtonColor: "#DD6B55",
	    			   confirmButtonText: "forward  now",
	    			   closeOnConfirm: false,
	    			 },
	    			 function(isConfirm){
	    				 if (isConfirm) {
	    					   window.location.href = "/spring-merchant/views/foods";
	    				}else{
	    					
	    				}
	    			 });
	    	   }
    	   
    	   if(res.data=="reject"){
    		   
    		   swal({
    			   title: "status",
    			   text: "you have be reject,forward to register page",
    			   type: "info",
    			   showCancelButton: false,
    			   confirmButtonColor: "#DD6B55",
    			   confirmButtonText: "forward  now",
    			   closeOnConfirm: false,
    			 },
    			 function(isConfirm){
    				 if (isConfirm) {
    					   window.location.href = "/spring-merchant/views/register/info";
    				}else{
    					
    				}
    			 });
    	   }
	    	   
       }
       if(res.code==2){
    	   swal({
			   title: "notify",
			   text: res.message+" forward to order page",
			   type: "info",
			   showCancelButton: true,
			   confirmButtonText: "forward now",
			   cancelButtonText:"cancle",
			   closeOnConfirm: false,
			   closeOnCancel: false
			 },
			 function(isConfirm){
				 if (isConfirm) {
					   window.location.href = "/spring-merchant/orders/detail?order_processNumber_id="+res.data;
				}else{
					swal("cancel");
				}
			 });
    	   
       }
       
       if(res.code==3){
    	   swal({
			   title: "notify",
			   text: res.data,
			   type: "info",
			   showCancelButton: true,
			   confirmButtonText: "confirm",
			   cancelButtonText:"cancle",
			   closeOnConfirm: false,
			   closeOnCancel: false
			 },
			 function(isConfirm){
				 if (isConfirm) {
					 swal("success");
				}else{
					swal("cancel");
				}
			 });
    	   
       }
    	
    }
    
}      
//       
//       if(res.code==1){
//    	   if(res.message=="WHITE_LIST"){
//    		  sweetAlert("status change","you have add to white list","info","forward?",false,function(isConfirm){
//    			  if (this.isConfirm) {
//    				   window.location.href = "/spring-merchant/views/orders";
//    			}
//    		  });
//    	   }
//       }
//       if(res.code==2){
//    	   var orderFun = function(isconfirm){
//  			  if (this.isConfirm) {
//				   window.location.href = "/spring-merchant/orders";
//			}else{
//				
//			}
//		  }
//    	   
//    	   sweetAlert("notify",res.data,"info","forward?",true,orderFun);
//       }
//    	
//    }
//    
//    
//    function sweetAlert(title,text,type,confirmButtonText,cancelButtonText,closeOnCancel,confirmFun){
//    	 swal({
//			   title: title,
//			   text: text,
//			   type: type,
//			   showCancelButton: true,
//			   confirmButtonColor: "#DD6B55",
//			   confirmButtonText: confirmButtonText,
//			   cancelButtonText:cancelButtonText,
//			   closeOnConfirm: false,
//			   closeOnCancel: closeOnCancel
//			 },
//			 function(isConfirm){
//				 confirmFun;
//			 });
//    }
//	
